import React, {Component} from 'react'
import {Link} from 'react-router'
import '../sass/SearchResult'

export default class SearchResult extends Component {
  constructor() {
    super()
  }

  render() {
    const {searchList, fetchAddToCart, scrollHandle} = this.props

    /*
      {
        "c_goods_id": "23432",\\商品ID,
        "c_goods_name": "1",\\名称
        "c_goods_class_name": "2",\\分类名称
        "c_goods_description": "新鲜水果",\\详情
        "c_goods_price": "3243",\\商品价格
        "c_goods_sales":23,\\销量
        "c_goods_picture": "http://222.76.27.50:9001/images/default/default_small.jpg",\\小图
        "c_goods_spce": null,\\规格
        "c_goods_gc_id": "2343",\\二级分类ID
        "c_goods_gc_parent_id": "324324",\\一级分类ID
        "c_goods_unit": ""\\单位
        "c_goods_inventory":"库存充足",//库存描述
         "c_goods_inventory_count":"234"//商品库存数量
       }

     */

    let html = []

    if (searchList && searchList.length) {
      searchList.map((item, i) => {
        html.push(
          <li key={i} className="search-result-item">
            <Link to={`/p/${item.c_goods_id}`}>
              <img src={item.c_goods_picture ? item.c_goods_picture : require('../images/goods_default.png')}/>
              <p className="title">
                {item.tag ? <i className="iconfont icon-shangpinbiaoqian tag"><span className="tag-text">{item.tag}</span></i> : ''}
                {item.c_goods_name}
              </p>
                <p className="sale-price">{item.isNewAdvance ? <span><span className="goods-price-sign">预售价</span> ¥{item.advancePrice}</span> : item.isAssemble ? <span><span className="goods-price-sign">套餐价</span> ¥{item.c_goods_price}</span> : item.salePrice ? <span><span className="goods-price-sign">企业专享价</span> ¥{item.salePrice}</span> : `￥${item.c_goods_price}`}/{item.c_goods_unit}</p>
              {/* <span className="weight">{item.c_goods_spce}/{item.c_goods_unit}</span>*/}
            </Link>
              {
                  item.goodsInventory ? item.c_goods_price &&
                      <i
                          className="iconfont icon-tianjiagouwuche add-cart"
                          onClick={fetchAddToCart.bind(this, {
                            count: '1',
                            goodsId: item.c_goods_id,
                            status: '1',
                            add: true
                          })}
                      ></i> : <span className="add-cart stock">已抢完</span>
              }
          </li>
        )
      })
    } else if (searchList && !searchList.length) {
      html.push(
        <li key="0" style={{textAlign: 'center', paddingTop: '1rem'}}>搜索结果不存在</li>
      )
    }

    return (
      <ul className="search-result">
        {html}
      </ul>
    )
  }
}
